package com.sgb.kjwl.view.ui.adapter.transport;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.utils.DefaultUtil;
import com.swgk.core.util.ArrayUtil;

import java.util.List;

/**
 * @author: 杨畔
 * @date: 2021/11/3 10:59
 * @Description: 货物类型选择适配器
 */
public class GoodsTypeChooseAdapter extends BaseQuickAdapter<GoodsInfoTypeEntity3, BaseViewHolder> {
    //选中下标
    private int mSelectIndex = -1;

    /**
     * item的类型
     * 0——表示是父类型（包括中间级）
     * 1——表示为子类型（最后一级）
     */
    private int type = -1;

    public GoodsTypeChooseAdapter(@Nullable List<GoodsInfoTypeEntity3> data) {
        super(R.layout.app_item_goods_type_choose, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsInfoTypeEntity3 item) {
        helper.setText(R.id.tv_name, DefaultUtil.getString(item.getName()))
                .setVisible(R.id.iv_arrow, ArrayUtil.isNotNullAndEmpty(item.getChildList()));

        if (mSelectIndex == helper.getLayoutPosition() && type == 0) {
            helper.getView(R.id.ll_root).setSelected(true);
            helper.getView(R.id.tv_name).setSelected(true);
        } else {
            helper.getView(R.id.ll_root).setSelected(false);
            helper.getView(R.id.tv_name).setSelected(false);
        }

        if (ArrayUtil.isNullOrEmpty(item.getChildList()) && type == 1) {
            helper.setVisible(R.id.iv_check, mSelectIndex == helper.getLayoutPosition());
        }
    }

    public void setSelectIndex(int selectIndex) {
        this.mSelectIndex = selectIndex;
        notifyDataSetChanged();
    }

    public int getmSelectIndex() {
        return mSelectIndex;
    }

    public void setmSelectIndex(int mSelectIndex) {
        this.mSelectIndex = mSelectIndex;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
}
